From 0bd542b54d619a52d49a5ffb2426104a2fa42392 Mon Sep 17 00:00:00 2001 From: "kaf24@freefall.cl.cam.ac.uk" Date: Fri, 27 Aug 2004 13:41:23 +0000 Subject: [PATCH] bitkeeper revision 1.1159.53.11 (412f3a03Su4nmVv7scE_x2v_aEs7fA) Change timestamp format exported by Xen. Now we provide all 64 bits of the processor's TSC. --- .../arch/xen/kernel/time.c | 11 ++++++++--- .../arch/xen/i386/kernel/time.c | 2 +- .../arch/xen/i386/kernel/timers/timer_tsc.c | 7 ++----- xen/arch/x86/time.c | 19 ++++++++----------- xen/include/hypervisor-ifs/arch-x86_32.h | 5 +---- xen/include/hypervisor-ifs/arch-x86_64.h | 9 +-------- 6 files changed, 21 insertions(+), 32 deletions(-) diff --git a/linux-2.4.27-xen-sparse/arch/xen/kernel/time.c b/linux-2.4.27-xen-sparse/arch/xen/kernel/time.c index 23aac6c308..a2ffce3039 100644 --- a/linux-2.4.27-xen-sparse/arch/xen/kernel/time.c +++ b/linux-2.4.27-xen-sparse/arch/xen/kernel/time.c @@ -214,7 +214,8 @@ static void __get_time_values_from_xen(void) rmb(); shadow_tv.tv_sec = HYPERVISOR_shared_info->wc_sec; shadow_tv.tv_usec = HYPERVISOR_shared_info->wc_usec; - shadow_tsc_stamp = HYPERVISOR_shared_info->tsc_timestamp.tsc_bits; + shadow_tsc_stamp = + (u32)(HYPERVISOR_shared_info->tsc_timestamp >> rdtsc_bitshift); shadow_system_time = HYPERVISOR_shared_info->system_time; rmb(); } @@ -604,6 +605,7 @@ void __init time_init(void) { unsigned long long alarm; u64 __cpu_khz, cpu_freq, scale, scale2; + unsigned int cpu_ghz; __cpu_khz = HYPERVISOR_shared_info->cpu_freq; do_div(__cpu_khz, 1000); @@ -615,8 +617,11 @@ void __init time_init(void) xtime.tv_usec = HYPERVISOR_shared_info->wc_usec; processed_system_time = shadow_system_time; - rdtsc_bitshift = HYPERVISOR_shared_info->tsc_timestamp.tsc_bitshift; - cpu_freq = HYPERVISOR_shared_info->cpu_freq; + cpu_freq = HYPERVISOR_shared_info->cpu_freq; + + cpu_ghz = do_div(cpu_freq, 1000000000UL); + for ( rdtsc_bitshift = 0; cpu_ghz != 0; rdtsc_bitshift++, cpu_ghz >>= 1 ) + continue; scale = 1000000LL << (32 + rdtsc_bitshift); do_div(scale, (u32)cpu_freq); diff --git a/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/time.c b/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/time.c index fbd059a5f7..10562570a8 100644 --- a/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/time.c +++ b/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/time.c @@ -160,7 +160,7 @@ static void __get_time_values_from_xen(void) rmb(); shadow_tv.tv_sec = s->wc_sec; shadow_tv.tv_usec = s->wc_usec; - shadow_tsc_stamp = s->tsc_timestamp.tsc_bits; + shadow_tsc_stamp = (u32)s->tsc_timestamp; shadow_system_time = s->system_time; rmb(); } diff --git a/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/timers/timer_tsc.c b/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/timers/timer_tsc.c index 05e370f932..7348d2a081 100644 --- a/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/timers/timer_tsc.c +++ b/linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/timers/timer_tsc.c @@ -78,7 +78,6 @@ static int count2; /* counter for mark_offset_tsc() */ */ static unsigned long fast_gettimeoffset_quotient; -unsigned int rdtsc_bitshift; extern u32 shadow_tsc_stamp; extern u64 shadow_system_time; @@ -91,7 +90,7 @@ static unsigned long get_offset_tsc(void) rdtsc(eax,edx); /* .. relative to previous jiffy (32 bits is enough) */ - eax -= (shadow_tsc_stamp << rdtsc_bitshift) & 0xffffffff; + eax -= shadow_tsc_stamp; /* * Time offset = (tsc_low delta) * fast_gettimeoffset_quotient @@ -119,7 +118,7 @@ static unsigned long long monotonic_clock_tsc(void) /* atomically read monotonic base & last_offset */ do { seq = read_seqbegin(&monotonic_lock); - last_offset = monotonic_offset << rdtsc_bitshift; + last_offset = monotonic_offset; base = monotonic_base; } while (read_seqretry(&monotonic_lock, seq)); @@ -349,8 +348,6 @@ static int __init init_tsc(char* override) "0" (eax), "1" (edx)); } - rdtsc_bitshift = HYPERVISOR_shared_info->tsc_timestamp.tsc_bitshift; - set_cyc2ns_scale(cpu_khz/1000); rdtscll(alarm); diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index dfe20e415d..48b2ce9762 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -44,15 +44,14 @@ static unsigned int rdtsc_bitshift; /* Which 32 bits of TSC do we use? */ static u64 cpu_freq; /* CPU frequency (Hz) */ static u32 st_scale_f; /* Cycles -> ns, fractional part */ static u32 st_scale_i; /* Cycles -> ns, integer part */ -static u32 tsc_irq; /* CPU0's TSC at last 'time update' */ +static u32 shifted_tsc_irq; /* CPU0's TSC at last 'time update' */ +static u64 full_tsc_irq; /* ...ditto, but all 64 bits */ static s_time_t stime_irq; /* System time at last 'time update' */ static unsigned long wc_sec, wc_usec; /* UTC time at last 'time update'. */ static rwlock_t time_lock = RW_LOCK_UNLOCKED; static void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - u64 full_tsc; - write_lock_irq(&time_lock); #ifdef CONFIG_X86_IO_APIC @@ -71,8 +70,8 @@ static void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) * Updates TSC timestamp (used to interpolate passage of time between * interrupts). */ - rdtscll(full_tsc); - tsc_irq = (u32)(full_tsc >> rdtsc_bitshift); + rdtscll(full_tsc_irq); + shifted_tsc_irq = (u32)(full_tsc_irq >> rdtsc_bitshift); /* Update jiffies counter. */ (*(unsigned long *)&jiffies)++; @@ -243,7 +242,7 @@ static inline u64 get_time_delta(void) rdtscll(tsc); low = (u32)(tsc >> rdtsc_bitshift); - delta_tsc = (s32)(low - tsc_irq); + delta_tsc = (s32)(low - shifted_tsc_irq); if ( unlikely(delta_tsc < 0) ) delta_tsc = 0; delta = ((u64)delta_tsc * st_scale_f); delta >>= 32; @@ -285,8 +284,7 @@ void update_dom_time(shared_info_t *si) wmb(); si->cpu_freq = cpu_freq; - si->tsc_timestamp.tsc_bitshift = rdtsc_bitshift; - si->tsc_timestamp.tsc_bits = tsc_irq; + si->tsc_timestamp = full_tsc_irq; si->system_time = stime_irq; si->wc_sec = wc_sec; si->wc_usec = wc_usec; @@ -328,7 +326,6 @@ void do_settime(unsigned long secs, unsigned long usecs, u64 system_time_base) int __init init_xen_time() { u64 scale; - u64 full_tsc; unsigned int cpu_ghz; cpu_ghz = (unsigned int)(cpu_freq / 1000000000ULL); @@ -341,9 +338,9 @@ int __init init_xen_time() st_scale_i = scale >> 32; /* System time ticks from zero. */ - rdtscll(full_tsc); + rdtscll(full_tsc_irq); stime_irq = (s_time_t)0; - tsc_irq = (u32)(full_tsc >> rdtsc_bitshift); + shifted_tsc_irq = (u32)(full_tsc_irq >> rdtsc_bitshift); /* Wallclock time starts as the initial RTC time. */ wc_sec = get_cmos_time(); diff --git a/xen/include/hypervisor-ifs/arch-x86_32.h b/xen/include/hypervisor-ifs/arch-x86_32.h index 04edd474ea..91a111bd92 100644 --- a/xen/include/hypervisor-ifs/arch-x86_32.h +++ b/xen/include/hypervisor-ifs/arch-x86_32.h @@ -104,10 +104,7 @@ typedef struct unsigned long ss; } PACKED execution_context_t; -typedef struct { - u32 tsc_bits; /* 0: 32 bits read from the CPU's TSC. */ - u32 tsc_bitshift; /* 4: 'tsc_bits' uses N:N+31 of TSC. */ -} PACKED tsc_timestamp_t; /* 8 bytes */ +typedef u64 tsc_timestamp_t; /* RDTSC timestamp */ /* * The following is all CPU context. Note that the i387_ctxt block is filled diff --git a/xen/include/hypervisor-ifs/arch-x86_64.h b/xen/include/hypervisor-ifs/arch-x86_64.h index 701084cec6..7ac8cf8a73 100644 --- a/xen/include/hypervisor-ifs/arch-x86_64.h +++ b/xen/include/hypervisor-ifs/arch-x86_64.h @@ -100,14 +100,7 @@ typedef struct unsigned long ss; } PACKED execution_context_t; -/* - * NB. This may become a 64-bit count with no shift. If this happens then the - * structure size will still be 8 bytes, so no other alignments will change. - */ -typedef struct { - u32 tsc_bits; /* 0: 32 bits read from the CPU's TSC. */ - u32 tsc_bitshift; /* 4: 'tsc_bits' uses N:N+31 of TSC. */ -} PACKED tsc_timestamp_t; /* 8 bytes */ +typedef u64 tsc_timestamp_t; /* RDTSC timestamp */ /* * The following is all CPU context. Note that the i387_ctxt block is filled -- 2.30.2